<?php
namespace common\components\wtools\validators;


use yii\validators\Validator;

class Username extends Validator
{
    public function validateAttribute($model, $attribute)
    {
        $username = $model->$attribute;
        $r = "/^[a-zA-Z\x{4e00}-\x{9fa5}_][a-zA-Z0-9\x{4e00}-\x{9fa5}_]+$/u";
        preg_match($r, $username, $arr);
        if (!$arr){
            $this->addError($model, $attribute, '账号格式错误');
        }
    }
}
